﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Loogn.DataAccess
{
    /// <summary>
    /// 字段修改器
    /// </summary>
    public class UpdateBuilder
    {
        Dictionary<string, object> dict;
        
        internal UpdateBuilder()
        {
            dict = new Dictionary<string, object>();
        }

        internal UpdateBuilder(string field, object value)
            : this()
        {
            dict[field] = value;
        }

        /// <summary>
        /// 设置字段
        /// </summary>
        /// <param name="field">字段名</param>
        /// <param name="value">字段的新值</param>
        /// <returns></returns>
        public UpdateBuilder Set(string field, object value)
        {
            dict[field] = value;
            return this;
        }

        internal Dictionary<string, object> SetDict
        {
            get
            {
                return dict;
            }
        }
    }

    /// <summary>
    /// 字段修改器的帮助类
    /// </summary>
    public static class Update
    {
        /// <summary>
        /// 设置字段
        /// </summary>
        /// <param name="field">字段名</param>
        /// <param name="value">字段新值</param>
        /// <returns></returns>
        public static UpdateBuilder Set(string field, object value)
        {
            return new UpdateBuilder(field, value);
        }

        /// <summary>
        /// 返回修改器实例
        /// </summary>
        /// <returns></returns>
        public static UpdateBuilder NewBuilder()
        {
            return new UpdateBuilder();
        }
    }
}
